{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "from kafka import KafkaProducer\n",
    "import pandas as pd\n",
    "import csv\n",
    "import time\n",
    "\n",
    "#Declaring producer API on LocalHost\n",
    "producer = KafkaProducer(bootstrap_servers=['localhost:9092'],api_version=(0,10))\n",
    "\n",
    "#Reading one of the datafile from the sensors on which the real-time prediction to be done.\n",
    "df = pd.read_csv(\"/home/wolvorine/Downloads/JXL_ITDS_trial2.csv\", header = \"infer\")\n",
    "interval = 1/142\n",
    "df['Time'] = df['Time'].apply(lambda x: int(str(x)[:-3]))\n",
    "df['Time'] = pd.to_datetime(df['Time'],unit='ms')\n",
    "df['Time'] = df['Time'].apply(lambda x: str(x).replace(\" \",\",\"))\n",
    "for row in df.values:\n",
    "    temp = str(row)\n",
    "    temp = temp.replace(\"[\",\"\")\n",
    "    temp = temp.replace(\"]\",\"\")\n",
    "    temp = temp.replace(\"\\n\",\"\")\n",
    "    temp = temp.replace(\" \",\";\")\n",
    "#Publishing the data row by row in the Kafka topic 'Test'\n",
    "    producer.send('test', temp.encode('utf-8'))\n",
    "    producer.flush()\n",
    "    time.sleep(interval)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
